//设计一个循环队列
class MyCircularQueue {
    public int[] elem;
    public int front; //队头下标
    public int rear; //队尾下标

    public MyCircularQueue(int k) {
        elem = new int[k+1]; //因为要浪费一个空间判断是否满，所以数组实际大小要k+1
        rear = front = 0;
    }

    public boolean enQueue(int value) {
        if(!isFull()){
            elem[rear] = value;
            rear = (rear+1)%elem.length;
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(!isEmpty()){
            front = (front+1)%elem.length;
            return true;
        }
        return false;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        return elem[(rear - 1 + elem.length) % elem.length];
    }

    public boolean isEmpty() {
        return front == rear;
    }

    public boolean isFull() {
        return (rear+1)%elem.length == front;
    }
}
